package com.test.lucene;

/**
 * Base class for exceptions thrown from the lucene project.
 * 
 * @author Patrick
 */
public class LuceneException extends Exception {

    /**
     * To allow the class to be serialised.
     */
    private static final long serialVersionUID = 4660694565879237095L;

    /**
     * @param msg
     *            for the exception.
     */
    public LuceneException(final String msg) {
        super(msg);
    }

    /**
     * Exception class which preserves the existing exception stack.
     * 
     * @param msg
     *            for the exception.
     * @param cause
     *            The cause of the exception.
     */
    public LuceneException(final String msg, final Throwable cause) {
        super(msg + getCauseMessage(cause), cause);
    }

    /**
     * Exception class which preserves the existing exception stack.
     * 
     * @param cause
     *            The cause of the exception.
     */
    public LuceneException(final Throwable cause) {
        super(getCauseMessage(cause), cause);
    }

    /**
     * Get the cause of the exception.
     * <p>
     * 12/05/2006 Discussed with Rick. Would like to add the message text from
     * the previous message to this exception. This will improve the message
     * returned to ColdFusion.
     * 
     * @param cause
     *            The cause of the exception.
     * @return A string containing the cause of the exception.
     */
    private static String getCauseMessage(final Throwable cause) {
        String msg = cause.getMessage();
        if (msg == null || msg.trim().length() == 0) {
            return "";
        } else {
            return " [" + msg + "]";
        }
    }
}
